package cn.looov.demo.future;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Demo1 {
	private ExecutorService executor = Executors.newSingleThreadExecutor();

	public Future<Integer> calculate(Integer input) {
		return executor.submit(() -> {
			System.out.println("Calculating11..." + input);
			Thread.sleep(1000);
			executor.shutdown();
			return input * input;
		});
	}

	
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		Demo1 demo1 = new Demo1();
//		Future<Integer> calculate = demo1.calculate(5);
//		System.out.println(calculate.get());
		Future<Integer> futureOne = demo1.calculate(20);
        while(!futureOne.isDone()) {
            System.out.println("Calculating...");
            Thread.sleep(300);
        }
        Integer result = futureOne.get();
        System.out.println(result);
	}
	
	public static void test1() {
		
		System.out.println(11);
	}
}
